﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace MusicLibraryGUI
{
    public interface ILogger
    {
        void Log(string message);
    }

    public class ConsoleLogger : ILogger
    {
        public void Log(string message)
        {
            Console.WriteLine(message);
        }
    }

    public class FileLogger : ILogger
    {
        private StreamWriter _sw;

        public FileLogger(string filename)
        {
            this._sw = new StreamWriter(filename);
        }

        ~FileLogger()
        {
            //_sw.Close();
        }

        public void Log(string message)
        {
            _sw.WriteLine(message);
            _sw.Flush();
        }
    }

    public interface ILoggerFactory
    {
        ILogger CreateLogger();
        ILogger CreateLogger(string filename);
    }

    public class ConsoleLoggerFactory : ILoggerFactory
    {
        public ILogger CreateLogger()
        {
            return new ConsoleLogger();
        }
        public ILogger CreateLogger(string filename)
        {
            return new ConsoleLogger();
        }
    }

    public class FileLoggerFactory : ILoggerFactory
    {
        public ILogger CreateLogger()
        {
            throw new Exception();
        }

        public ILogger CreateLogger(string filename)
        {
            return new FileLogger(filename);
        }
    }

}
